package pl.edu.agh.xls2html.htmlelements;

import static org.junit.Assert.*;

import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.junit.Before;
import org.junit.Test;

public class TableTest {
	
	private HSSFWorkbook wb;	
	private HSSFSheet sheet;
	private HSSFRow row;		
	private HSSFCell cell;
//	private HSSFCell cell2;
	
	private Document doc;
	private Cell testCell;	
	private Table testTable;

	@Before
	public void setUp() throws Exception {
		wb = new HSSFWorkbook();
		sheet =  wb.createSheet();		
	}	

	@Test
	public void testEmptyTableHTML(){
		testTable = new Table(sheet,wb,doc);
		assertEquals(0, testTable.getRowsNum());
		assertEquals("<table cellpadding=\"0\"  cellspacing=\"0\" >\n</table>\n", testTable.getHTML());
	}
	
	@Test
	public void testEmptyTableCSS(){
		testTable = new Table(sheet,wb,doc);
		assertEquals(0, testTable.getRowsNum());
		assertEquals("", testTable.getCSS());
	}
	
	@Test
	public void testRowsNum(){
		row = sheet.createRow(0);		
		cell = row.createCell(0);
		cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC);
		cell.setCellValue(1);
		doc = new Document(wb);
		testTable = new Table(sheet,wb,doc);		
		assertEquals(1, testTable.getRowsNum());
	}
	
	@Test
	public void testColumnsNum(){
		row = sheet.createRow(0);		
		cell = row.createCell(0);
		cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC);
		cell.setCellValue(1);
		doc = new Document(wb);
		testTable = new Table(sheet,wb,doc);		
		assertEquals(1, testTable.getColumnsNum());
	}
	
	@Test
	public void testTableHTML(){		
		row = sheet.createRow(0);
		cell = row.createCell(0);		
		doc = new Document(wb);
		doc.setStaticMode();
		
		testTable = new Table(sheet,wb,doc);
		
		assertEquals("<table cellpadding=\"0\"  cellspacing=\"0\" >\n"+
			"\t<tr>\n"+
				"\t\t<td class=\"A1\" ><div>&nbsp;</div></td>\n"+
			"\t</tr>\n"+
			"</table>\n", testTable.getHTML());
	}
	
	@Test
	public void testTableCSS(){		
		row = sheet.createRow(0);
		cell = row.createCell(0);		
		doc = new Document(wb);
		doc.setStaticMode();
		
		testTable = new Table(sheet,wb,doc);
		testCell = new Cell(cell,wb,doc);
		assertEquals(testCell.getCSS(), testTable.getCSS());
	}

}
